import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomUserPermission } from '@/shared/model/room-user-permission.model';
import RoomUserPermissionService from './room-user-permission.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomUserPermissionDetails extends Vue {
  @Inject('roomUserPermissionService') private roomUserPermissionService: () => RoomUserPermissionService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomUserPermission: IRoomUserPermission = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomUserPermissionId) {
        vm.retrieveRoomUserPermission(to.params.roomUserPermissionId);
      }
    });
  }

  public retrieveRoomUserPermission(roomUserPermissionId) {
    this.roomUserPermissionService()
      .find(roomUserPermissionId)
      .then(res => {
        this.roomUserPermission = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
